#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;
using vegl = vector < pair < int, ll > >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1.5e5 + 10;

int n, Q, A, x[N];
veg G[N];

namespace L {
	const int N = 3e5 + 10;
	const int K = 21;
	int stk[N], dep[N], tot, dfn[N], R[N], mn[K + 1][N], lg[N], pw[K + 10];
	ll tdep[N];
	void dfs(int x, int p) {
		stk[dfn[x] = R[x] = ++tot] = x; dep[x] = dep[p] + 1; int y, w;
		for(auto v : G[x]) {
			tie(y, w) = v; if(y == p) continue;
			tdep[y] = tdep[x] + w; dfs(y, x); stk[R[x] = ++tot] = x; 
		}
	}
	inline int tmn(int x, int y) { return dep[x] < dep[y] ? x : y; }
	inline int LCA(int x, int y) { if(dfn[x] > dfn[y]) swap(x, y); x = dfn[x]; y = R[y]; int k = lg[y - x + 1]; return tmn(mn[k][x], mn[k][y - pw[k] + 1]); }
	inline ll dis(int x, int y) { return tdep[x] + tdep[y] - tdep[LCA(x, y)] * 2; }
	void build() {
		dfs(1, 0); rep(i, 2, tot) lg[i] = lg[i >> 1] + 1;
		pw[0] = 1; rep(i, 1, K) pw[i] = pw[i - 1] * 2;
		rep(i, 1, tot) mn[0][i] = stk[i];
		rep(i, 1, K) rep(j, 1, tot - pw[i] + 1) mn[i][j] = tmn(mn[i - 1][j], mn[i - 1][j + pw[i - 1]]);
	}
}

namespace T {
	int fa[N], siz[N], son[N], rt;
	vegl val[N], vfa[N];
	bool vis[N];
	void gsz(int x, int p) {
		siz[x] = 1; son[x] = 0; for(auto v : G[x]) if(!vis[v.fi] && v.fi ^ p) gsz(v.fi, x), siz[x] += siz[v.fi], chkmax(son[x], siz[v.fi]);
	}
	void grt(int x, int p, int tsz) {
		for(auto v : G[x]) if(!vis[v.fi] && v.fi ^ p) grt(v.fi, x, tsz); chkmax(son[x], tsz - siz[x]); if(rt == 0 || son[x] < son[rt]) rt = x;
	}
	int divide(int x) {
		gsz(x, 0); rt = 0; grt(x, 0, siz[x]); x = rt; vis[x] = true;
		for(auto v : G[x])
			if(!vis[v.fi]) fa[divide(v.fi)] = x;
		return x;
	}
	void upd(int tx) {
		int u = tx;
		while(u) {
			val[u].eb(x[tx], L :: dis(tx, u));
			if(fa[u]) vfa[u].eb(x[tx], L :: dis(tx, fa[u]));
			u = fa[u];
		}
	}
	ll query(int a, int b, const vegl &t, ll tdis) {
		int lpos = lower_bound(t.begin(), t.end(), pair < int, ll > { a, -514 }) - t.begin();
		int rpos = lower_bound(t.begin(), t.end(), pair < int, ll > { b + 1, -114 }) - t.begin() - 1;
		return lpos > rpos ? 0 : t[rpos].se - (lpos == 0 ? 0 : t[lpos - 1].se) + tdis * (rpos - lpos + 1);
	}
	ll query(int x, int a, int b) {
		ll res = 0; int lst = 0, lx = x;
		while(x) {
			res += query(a, b, val[x], L :: dis(lx, x));
			if(lst) res -= query(a, b, vfa[lst], L :: dis(lx, x));
			lst = x; x = fa[x];
		} return res;
	}
	void init(int x) {
		sort(val[x].begin(), val[x].end()); sort(vfa[x].begin(), vfa[x].end());
		ll lst = 0; for(auto &v : val[x]) v.se += lst, lst = v.se;
		lst = 0; for(auto &v : vfa[x]) v.se += lst, lst = v.se;
	}
	void build() { divide(1); rep(i, 1, n) upd(i); rep(i, 1, n) init(i); }
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in, Q = in, A = in; rep(i, 1, n) x[i] = in;
	rep(i, 2, n) { int u = in, v = in, w = in; G[u].eb(v, w), G[v].eb(u, w); }
	L :: build(); T :: build(); ll ans = 0;
	while(Q--) {
		int u = in; ll l = lin, r = lin; l = (l + ans) % A, r = (r + ans) % A;
		if(l > r) swap(l, r); ans = T :: query(u, l, r); printf("%lld\n", ans);
	}
	return 0;
}
